package com.platform.modules.report.controller;


import com.platform.common.utils.MapUtil;
import com.platform.common.utils.NumberUtils;
import com.platform.modules.report.dto.BaseItemDTO;
import com.platform.modules.sys.controller.AbstractController;
import com.platform.modules.sys.dao.SysCityAreaDao;
import com.platform.modules.sys.entity.SysCityAreaEntity;
import com.platform.modules.sys.entity.SysDictEntity;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class BaseReportController extends AbstractController {

    @Autowired
    SysCityAreaDao sysCityAreaDao;

    public List months = Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12");

    public List<SysCityAreaEntity> getAreas(String xzqh){
        return sysCityAreaDao.selectList(MapUtil.of("pid",xzqh));
    }


    /**
     *
     * @param map
     * @param areas
     * @return
     */
    public List<BaseItemDTO> buildAreaItem(Map<String,Object> map, List<SysCityAreaEntity> areas){
        List<BaseItemDTO> data = new ArrayList<>(areas.size());
        areas.forEach(e->{
            String xzqh = e.getId();
            data.add(new BaseItemDTO(e.getName(), map.getOrDefault(xzqh,0), xzqh));
        });
        return data;
    }

    public List<BaseItemDTO> buildStringItem(Map<String,Object> map, List<String> years){
        List<BaseItemDTO> data = new ArrayList<>(years.size());
        years.forEach(year ->{
            data.add(new BaseItemDTO(year, map.getOrDefault(year,0), year));
        });
        return data;
    }

    public List<BaseItemDTO> buildDictItem(Map<String,Object> map, List<SysDictEntity> dicts){
        List<BaseItemDTO> data = new ArrayList<>(dicts.size());
        dicts.forEach(dict ->{
            data.add(new BaseItemDTO(dict.getName(), map.getOrDefault(dict.getValue(),0), dict.getValue()));
        });
        return data;
    }



}
